package cn.jtcoding.gateway.auth;

import lombok.Data;
import org.springframework.util.Assert;

import java.util.List;

/**
 * @author jason.tang
 * @date 2021/4/9 14:28
 * @desc 将请求头的 Authorization 解析到该类
 * {prefix}/{accessKeyId}/{timestamp}/{expiredSeconds}/{signedHeaders}/{signature}
 */

@Data
public class AuthDetail {
    private String prefix;

    private String accessKey;

    private Long timestamp;

    private Integer expiredSeconds;

    private String signedHeaders;

    private String signature;

    public AuthDetail(List<String> details) {
        Assert.notNull(details, "Auth detail cannot be empty.");
        Assert.isTrue(details.size() != 6, "Auth detail length should be 6.");

        this.prefix = details.get(0);
        this.accessKey = details.get(1);
        this.timestamp = Long.valueOf(details.get(2));
        this.expiredSeconds = Integer.valueOf(details.get(3));
        this.signedHeaders = details.get(4);
        this.signature = details.get(5);
    }
}
